package cn.edu.ujn.ch04;

import java.util.List;

import javax.management.Query;


import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import cn.edu.ujn.ch04.db.HibernateSessionFactory;
import cn.edu.ujn.ch04.model.Detail;
import cn.edu.ujn.ch04.model.Login;
import javafx.scene.shape.QuadCurve;

public class testLogin {
	@Test
	public void addLogin() {
		Detail d=new Detail();
		d.setTruename("倪庆瑞");
		d.setEmail("123@ujn.edu.cn");
		Login l = new Login();
		l.setUsername("nqr");
		l.setPassword("123");
		l.setDetail(d);
		d.setLogin(l);
	Session session = HibernateSessionFactory.getSession();
	Transaction bt = session.beginTransaction();
	session.save(d);
	bt.commit();
	HibernateSessionFactory.closeSession();
		
		
		
	}
	@Test
	public void findAllLogin() {
		Session session=HibernateSessionFactory.getSession();
		Transaction bt=session.beginTransaction();
		org.hibernate.query.Query<Login> query = session.createQuery("from Login");
		List<Login> list = query.list();
		for(Login ll:list)
		{
			System.out.println(ll.getDetail().getTruename());
		}
		bt.commit();
		HibernateSessionFactory.closeSession();
	}

}
